package com.game.views
{
	import com.module.bag.BagManager;
	import com.module.mail.MailManager;
	
	import main.ChatPanel;
	import main.MenuPanel;
	import main.RoleInfoPanel;
	
	import managers.DragManager;
	
	import mx.core.Container;
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class UIMediator extends Mediator
	{
		public static const NAME:String = "UIMediator";
		
		public static const OpenMailPanel:String = "open mail panel";
		public static const CloseMailPanel:String = "close mail panel";
		public static const ShowMailContent:String = "show mail content";
		public static const OpenSendMail:String = "open to send mail";
		public static const CloseMailDetail:String = "close mail detail";
		public static const OpenBagBox:String = "open bag box";
		public static const CloseBagBox:String = "close bag box";
		
		
		private var chatpanel:ChatPanel;
		private var roleinfopanel:RoleInfoPanel;
		private var menupanel:MenuPanel;
		private var dragManager:DragManager;
		public function UIMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			chatpanel = viewComponent.chat;
			roleinfopanel = viewComponent.roleinfo;
			menupanel = viewComponent.menu;
			dragManager = new DragManager(viewComponent as Container);
			(viewComponent.poppanels as Container).removeAllChildren();
		}
		
		public function get ui():RpgUi
		{
			return viewComponent as RpgUi;
		}
		
		override public function listNotificationInterests():Array
		{
			return [OpenMailPanel,CloseMailPanel,ShowMailContent,OpenSendMail,CloseMailDetail,//邮件
					OpenBagBox,CloseBagBox //背包
			];
		}
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName()){
				case OpenMailPanel:
					MailManager.instance.initMailPanel();
					PopUpManager.addPopUp(MailManager.instance.panel,this.ui);
					PopUpManager.centerPopUp(MailManager.instance.panel);
					break;
				case CloseMailPanel:
					PopUpManager.removePopUp(MailManager.instance.panel);
					break;
				case ShowMailContent:
					PopUpManager.addPopUp(MailManager.instance.detail,this.ui);
					PopUpManager.centerPopUp(MailManager.instance.detail);
					break;
				case OpenSendMail:
					MailManager.instance.toSend();
					PopUpManager.addPopUp(MailManager.instance.detail,this.ui);
					PopUpManager.centerPopUp(MailManager.instance.detail);
					break;
				case CloseMailDetail:
					PopUpManager.removePopUp(MailManager.instance.detail);
					break;
				case OpenBagBox:
					BagManager.instance.initBagPanel();
					PopUpManager.addPopUp(BagManager.instance.bag,this.ui);
					PopUpManager.centerPopUp(BagManager.instance.bag);
					break;
				case CloseBagBox:
					PopUpManager.removePopUp(BagManager.instance.bag);
					break;
			}
		}
	}
}